package by.vr.jpa.result.transformer.impl;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import by.vr.jpa.result.transformer.api.EntityInstantiator;

public class ProxyEntityInstantiator implements EntityInstantiator {
	
	

	public <T> T instantiate(Class<T> clazz) {
		final MethodInterceptor methodInterceptor = new LazyEntityInterceptor();

		final Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(methodInterceptor);
		return (T) enhancer.create();
	}

}
